require(["common", "jQuery", "coAjax", "hash_routie", "queryString", "href"], function(jSouper, $, coAjax, hash_routie, QueryString, href) {
	var queryString = new QueryString();
	var mid_bus_id = queryString.get("mid");

	App.set("$Event.newbus.build_bus", function() {
		var newbus_info = App.get("$Cache.newbus");
		if (!newbus_info.name) {
			alert('warn', '请输入用户名');
			return
		};
		if (!newbus_info.title) {
			alert('warn', '请输入店铺名称');
			return
		};
		if (!newbus_info.password) {
			alert('warn', '请输入密码');
			return
		};
		if (!newbus_info.confirm_password) {
			alert('warn', '请再次输入密码');
			return
		};
		if (!newbus_info.mobile_phone) {
			alert('warn', '请输入手机号');
			return
		};
		if (!newbus_info.email) {
			alert('warn', '请输入邮箱');
			return
		};
		if (!newbus_info.phone_code) {
			alert('warn', '请输入验证码');
			return
		};
		alert("申请提交中中");
		newbus_info.pid = mid_bus_id
		newbus_info.is_secondary_domain = !newbus_info.use_self_domain;
		newbus_info.domain = newbus_info.is_secondary_domain ? newbus_info.name : newbus_info.domain;
		coAjax.post(appConfig.open.register_with_domain_build, newbus_info, function(result) {
			alert("success", "申请已成功提交");
			App.set('IsPay', true);
			App.set("$Cache.newbus", {});
			myConfirm("您的微站已开通成功！\n首次开通赠送1个月使用时间！\n您的微站网址为：http://" + result.result._id + ".dotnar.com\n请到：http://admin.dotnar.com登录查看\n关于微站操作及开通信息已发送至您的邮箱，请注意查收！", function() {})
		}, function(errorCode, xhr, errorMsg) {
			alert("error", errorMsg);
			//重新获取验证码
			App.set("$Cache.newbus.wite_server", false);
		});
	});
	var _ti;

	function _phone_code_time(argument) {
		clearInterval(_ti);
		var _s = 60;
		_ti = setInterval(function() {
			_s -= 1;
			App.set("$Cache.newbus.next_phone_code_time", _s);
			if (_s === 0) {
				clearInterval(_ti);
				App.set("$Cache.newbus.wite_server", false);
			}
		}, 1000);
	};
	//请求验证码
	App.set("$Event.newbus.get_register_code", function() {
		if (!App.get('$Cache.newbus.mobile_phone')) {
			alert('warn', '请输入手机号');
			return
		};
		App.set("$Cache.newbus.wite_server", true);
		coAjax.get(appConfig.open.register_code, {
			mobile_phone: App.get("$Cache.newbus.mobile_phone")
		}, function(result) {
			alert(result.result);
			_phone_code_time();
		}, function(errorCode, xhr, errorMsg) {
			alert("error", errorMsg);
			App.set("$Cache.newbus.wite_server", false);
		});
	});
});